package com.example.rabbitmq.receive;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Timer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RabbitListener(queues = "hello")
public class ReceivingMessage {
    @Autowired
    private Timer responses;
    @Autowired
    private Counter pendingJobs;
    @RabbitHandler
    public void processMessage(String queueMsg){
        final Timer.Context context = responses.time();
        pendingJobs.inc();
        pendingJobs.getCount();
        log.info("计数器 Count ：" + pendingJobs.getCount());
        log.info("Receiving a Message : {}" + queueMsg);
        context.stop();
    }

}